import entity.CardCollection;
import entity.CreditCard;
import util.Storer;

import java.util.List;
import java.util.Scanner;

public class SetUp {
    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) throws Exception{
        Storer.read();

        while(true){
            System.out.println("请输入你要查找的卡号或持卡人姓名：(输入exit退出)");
            String input = scanner.nextLine();
            if("exit".equals(input)){
                System.out.println("退出程序");
                break;
            }

            boolean flag = false;
            for (CreditCard card : CardCollection.getInstance().cards) {
                if (card.getNumber().equals(input) || card.getHolderName().equalsIgnoreCase(input)) {
                    flag = true;
                    System.out.println("找到匹配的卡：");
                    System.out.println("卡号：" + card.getNumber());
                    System.out.println("持卡人姓名：" + card.getHolderName());
                    System.out.println("发行机构："+card.getIssuer());
                    break;
                }
            }

            if(!flag){
                System.err.println("没有匹配的卡！请检查你的输入信息！");
            }

            Thread.sleep(200);
            System.out.println();
        }

        Storer.write();
    }
}
